package com.example.administrator.idocment;

import android.content.ContentResolver;
import android.content.Context;

import java.util.List;

/**
 * Created by Administrator on 2017/7/15 0015.
 */
public abstract class BaseTypeFind<T>
{

    protected Context context;

     protected  ContentResolver contentResolver;
    public BaseTypeFind(Context context)
    {
        this.context=context;
         contentResolver=context.getContentResolver();
    }





    public abstract void select();


    public abstract List<T> getListInfo();

    public  static String getFileSzie(Long length) {

        if (length >= 1048576) {
            return (length / 1048576) + "MB";
        } else if (length >= 1024) {
            return (length / 1024) + "KB";
        } else if (length < 1024) {
            return length + "B";
        } else {
            return "0KB";
        }

    }

    /*
    *  Uri[] fileUri = null;
                    fileUri = new Uri[]{MediaStore.Files.getContentUri("external")};
    *
                    //构造筛选语句
//                    String selection = MediaStore.Files.FileColumns.SIZE+" >="+(700*800)+" " ;
                 String selection ="";
                    for (int i = 0; i < extension.length; i++) {
                        if (i != 0) {
                            selection +=" OR ";
                        }
                        selection = selection + MediaStore.Files.FileColumns.MIME_TYPE + " LIKE '%" + extension[i] + "'";
                    }
                 String sort=MediaStore.Files.FileColumns.DATE_MODIFIED+ " ASC"+","+MediaStore.Files.FileColumns.DATE_ADDED+" ASC";
                ;
                 if(flag==picFlag)
                 {
                     selection+=" AND "+MediaStore.Files.FileColumns.SIZE+" >="+(512*512);
                     //sort= MediaStore.Images.ImageColumns.DATE_MODIFIED + "  ASC";
                 }


                   String[] colums = new String[]{MediaStore.Files.FileColumns.DATA,MediaStore.Files.FileColumns.TITLE,MediaStore.Files.FileColumns.PARENT,MediaStore.Files.FileColumns.SIZE,MediaStore.Files.FileColumns.DATE_MODIFIED};
                    //获取内容解析器对象
                    ContentResolver resolver = context1.getContentResolver();
                   // String sort= MediaStore.Files.FileColumns.SIZE+ " ASC"+","+MediaStore.Files.FileColumns._ID+" ASC";

                    //获取游标
                    for (int i = 0; i < fileUri.length; i++) {
                        Cursor cursor = resolver.query(fileUri[i], colums, selection, null ,sort);
                        if (cursor == null) {
                            return null;
                        }//游标从最后开始往前递减，以此实现时间递减顺序（最近访问的文件，优先显示）

                        long beginTime = System.currentTimeMillis();
                        if (cursor.moveToLast()) {

                            do {
                                //输出文件的完整路径
                                String data = cursor.getString(0);

                                Log.e("selectModel"," "+cursor.getString(0)+" Title:"+cursor.getString(1)+" Parent:"+cursor.getString(2)+" Size:"+cursor.getString(3));

                                Log.e("picTime", TimerFactory.create(TimerFactory.YearFormat).paseTimer(cursor.getLong(4)));
                                //if(cursor.getInt(3)>512*512)
                                paths.add(data);

                            } while (cursor.moveToPrevious());

                        }
                        cursor.close();
                    }
                    Log.e("picTime","Len:"+paths.size());
    *
    * */


}
